/*
 * keylist_example.c: Do fun things with keylists.
 */
#include <sharp-keylist.h>
#include <sharp-alloc.h>
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    /* Get a list pointer and initialize it */
    sharp_keylist *list;
    sharp_keylist_init(&list);

    char *keys[] = {"moo", "Lelouch Lamperouge", "QB", "jackfrost"};
    int *i = sharp_malloc(sizeof(int));
    *i = 0xFF;

    /* We'll insert some dummy values so it actually does something */
    sharp_keylist_insert(&list, keys[0], "more dumb constants");
    sharp_keylist_insert(&list, keys[1], "commands you: die!");
    sharp_keylist_insert(&list, keys[2], "Being meduka is suffering");
    sharp_keylist_insert(&list, keys[3], i); // an int for the heck of it

    /* Now retrieve them again, and show them to the user */
    int j;
    char *out;
    for(j = 0; j<=2; j++) {
        if(sharp_keylist_get(list, keys[j], (void*)&out))
            if(!out)
                printf("%s is NULL?!\n", keys[j]);
            else
                printf("%s: %s\n", keys[j], out);
        else
            printf("key not found: %s\n", keys[j]);
    }

    /* For safety reasons, you should also check for failure here, but I've
     * already made my point.
     */
    sharp_keylist_get(list, keys[3], (void*)&i);
    printf("%s: %d\n", keys[3], *i);
    free(i);

    return EXIT_SUCCESS;
}

